using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerHealthUI : MonoBehaviour
{
    Text levelText;
    Image healthSlider;
    Image expSlider;
    private void Awake()
    {
        levelText = transform.GetChild(2).GetChild(0).GetComponent<Text>();
        healthSlider = transform.GetChild(0).GetChild(0).GetComponent<Image>();
        expSlider = transform.GetChild(1).GetChild(0).GetComponent<Image>();
    }
    private void Update()
    {
        if (GameManager.Instance.playerStat != null)
        {
            levelText.text = GameManager.Instance.playerStat.characterData.currentLevel.ToString();
            UpdateHealth();
            UpdateExp();
        }
    }
    void UpdateHealth()
    {
        float healthPrecent = (float)GameManager.Instance.playerStat.CurrentHealth / GameManager.Instance.playerStat.MaxHealth;

        healthSlider.fillAmount = healthPrecent;
    }
    void UpdateExp()
    {
        float expPrecent = (float)GameManager.Instance.playerStat.characterData.currentExp / GameManager.Instance.playerStat.characterData.baseExp;

        expSlider.fillAmount = expPrecent;
    }
}
